package com.heima.add;

import com.heima.domain.GetIndex;
import com.heima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class AddStudent {
    public void addStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        GetIndex getIndex = new GetIndex();
        String id;
        while (true) {
            System.out.println("请输入学生学号:");
            id = sc.next();
            int index =getIndex.getIndex(list,id);
            if(index == -1){
                break;
            }else{
                System.out.println("您输入的学号已被占用,请重新输入!");
            }
        }
        System.out.println("请输入学生姓名:");
        String name = sc.next();
        System.out.println("请输入学生年龄:");
        int age = sc.nextInt();
        System.out.println("请输入学生生日:");
        String birthday = sc.next();
        Student stu = new Student(id,name,age,birthday);
        list.add(stu);
        System.out.println("添加成功");
    }
}
